Javascript Code to Replace Specific Old-Link in Whole Web/Blog with New Link

How to replace link a whole of blog or website pages with javascript code.

 Hey everyone, in this page I will share a tutorial and the javascript code. This code use for replacing a specific link in whole of your website/blog with the new link. 

For instance, in all of the pages in your blog there are link: https://oldlink.com/abc , https://oldlink.com/def, https://oldlink.com/ijk ....

You want to replace https://oldlink.com/ with https://newlink.com. And if you want it, let us do it.

[post_ads]

Javascript Replace All specific link in Whole of Web/Blog

Javascript as a popular language that used to build a web/blog. May be its too old, but still be the favorites one.

From the example above, it will spend to much time if you editing each of page. Imagine if you have 400 pages. Save your time to editing one by one page!

You can use this simple code. To see the script, share this page in your social media, then visit this page from your shared link.
[lock]
[
    <script> //<![CDATA[
function replaceLinksInWholeWebsite() {
  var elements = document.getElementsByTagName('a');

  for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    var href = element.getAttribute('href');

    // Check if the link starts with "https://www.oldlink.com/"
    if (href && href.startsWith('https://www.oldlink.com/')) {
      // Replace the old link with "https://www.newlink.com/"
      element.setAttribute('href', href.replace('https://www.oldlink.com/', 'https://www.newlink.com/'));
    }
  }
}

// Usage:
replaceLinksInWholeWebsite();

//]]> </script>
]
[/locked]

How to do That?

First, from code above. Replace https://www.oldlink.com/ with the link that you want remove. Then, change https://www.newlink.com, with your new destination link.
[post_ads_2]
[ATID-563 Tsubaki Sannomiya mixdrop.co/f/gnrmedeluvx8jd]

After that, It will be a question "Where I have to place the code?"

You only need to put the code in your HTML template editor. Place the code above </body> tag. You can use this code in all of web/blog that build with javascript. Included blogger (blogspot) or Wordpress.
Javascript Code to Replace Specific Old-Link

COMMENTS

Name

android,1,business,19,celebrity,4,cloud,25,coding,1,Education,60,Entertain,11,Finance,16,Gaming,8,healthy,9,insurance,1,ios,2,javascript,3,kpop,1,Lifestyle,27,linux,6,mac os,1,math,1,movie,4,music,5,News,3,parenting,6,phone,2,recipe,1,SEO,3,Sport,4,Tech,34,tips,2,windows,1,
ltr
item
enCek: Javascript Code to Replace Specific Old-Link in Whole Web/Blog with New Link
Javascript Code to Replace Specific Old-Link in Whole Web/Blog with New Link
How to replace link a whole of blog or website pages with javascript code.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmLAt7l9GyYPn3D0GPZK0h5KUnBYNqXw74L8IcW8lY7b0TC5S2JZsgZbGrUE9Pvd23PZ3SSioyzlu2jHcx0t8ziBEaJXxNUrt2NJFr2jrDo96tYiKLjq1t8XyiWdvUjbYKe-HJBbXuP9teiHfd-vq9N1YdwCVaeF54eaMURAA7lfb0jcA-vJefAFKdYVc/w320-h260/istockphoto-1309893470-612x612.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmLAt7l9GyYPn3D0GPZK0h5KUnBYNqXw74L8IcW8lY7b0TC5S2JZsgZbGrUE9Pvd23PZ3SSioyzlu2jHcx0t8ziBEaJXxNUrt2NJFr2jrDo96tYiKLjq1t8XyiWdvUjbYKe-HJBbXuP9teiHfd-vq9N1YdwCVaeF54eaMURAA7lfb0jcA-vJefAFKdYVc/s72-w320-c-h260/istockphoto-1309893470-612x612.jpg
enCek
https://en.cekrisna.com/2023/06/javascript-code-to-replace-a-link-whole-of%20web-blog.html
https://en.cekrisna.com/
https://en.cekrisna.com/
https://en.cekrisna.com/2023/06/javascript-code-to-replace-a-link-whole-of%20web-blog.html
true
7896735586237684417
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content